<template>
  <header>
    <span @click.stop="$back"><el-icon size="18">
        <Back />
      </el-icon></span>
    <dl>
      <dd v-for="(item, index) in tab" :class="activeindex == index ? 'active' : ''" @click="activeindex = index">
        {{ $t(item) }}
      </dd>
    </dl>
    <strong></strong>
  </header>
  <main class="main">
    <template v-if="activeindex == 0">
      <Skeleton :loading="loading">
        <template #ske>
          <div style="
            width: 100%;
            display: flex;
            justify-content: start;
            align-items: center;
            padding: 0 16px;
          ">
            <van-skeleton-paragraph style="width: 60px; height: 36px; margin: 10px 10px 0px 0" />
            <van-skeleton-paragraph style="width: 60px; height: 36px; margin: 10px 0 0px 0" />
          </div>
        </template>
        <template #main>
          <ul>
            <li v-for="(item, index) in bar" :class="activeBindex == index ? 'activeB' : ''"
              @click="activeBindex = index">
              <img :src="item.img" alt="" />
              <strong>{{ item.name }}</strong>
            </li>
          </ul>
        </template>
      </Skeleton>

      <component :loading="loading" :is="activeBindex == 0 ? BRL : USDT" />
    </template>
    <template v-else>
      <dl class="record" v-if="recordinfo.list.length != 0">
        <dd v-for="(item, index) in recordinfo.list" :key="index">
          <p class="time">{{ item.date }}</p>
          <div class="record-item" v-for="child in item.data " :key="child.orderID">
            <div>
              <p>{{ $t('language.rechange.orderID') }}: {{ child.orderID }}</p>
              <i @click="copyToClipboard(child.orderID, proxy)">{{ $t('language.rechange.copy') }}</i>
            </div>
            <span>{{ $t('language.rechange.RechargeAmount') }}: <strong>{{ child.amount / 100 }}R$</strong></span>
            <div class="status">
              <strong>{{ child.orderDate }}</strong>
              <span v-if="child.orderStatus == 0">{{ $t('language.rechange.waitpay') }}</span>
              <span v-else style="color: #0c730c;">{{ $t('language.rechange.paysuccess') }}</span>

            </div>
          </div>
        </dd>
      </dl>
      <div class="nodata" v-if="recordinfo.list.length == 0 && !loadingrecord">
        <img src="@/assets/img/bg4.png" alt="" />
        <p>{{ $t("language.rechange.tips") }}</p>
      </div>
    </template>
  </main>
</template>
<script setup lang="ts">
// const { proxy } = getCurrentInstance();
import { copyToClipboard } from "@/utils/common";
import { reactive, ref, getCurrentInstance, nextTick, watch } from "vue";
import BRL from "../component/rechangeBRL.vue";
import USDT from "../component/rechangeUSDT.vue";
import { useRoute } from "vue-router"
const router: any = useRoute()
const { proxy } = getCurrentInstance();
const getImg = (url) => {
  return new URL(`../../../assets/img/${url}`, import.meta.url).href;
};
let loading = ref(true);
let activeindex = ref(0);

if (Object.keys(router.query).length != 0) {
  activeindex.value = router.query.index
} else {
  activeindex.value = 0
}
let activeBindex = ref(0);
let tab = reactive(["language.rechange.title1", "language.rechange.title2"]);
let bar = reactive([
  {
    img: getImg("mylrft.png"),
    name: "BRL",
  },
  {
    img: getImg("t1.png"),
    name: "USDT",
  },
]);
//获取充值数据
let info = JSON.parse(localStorage.getItem("info"));
//获取充值记录
let record = reactive({
  id: info.gameID,
  pageIndex: 1,
  pageSize: 30
})
let recordinfo = reactive({
  list: [],
  pageIndex: 1,
  pageSize: 11,
  totalCount: 23
})
let loadingrecord = ref(false)
watch(() => activeindex.value, (newValue) => {
  if (newValue == 1) {
    loadingrecord.value = true
    ElLoading.service({
      lock: true,
      background: 'rgba(0, 0, 0, 0.7)',
      customClass: 'el-loading'
    })
    proxy
      .$post(`/Payment/v1.0/Web/User/Recharge/List`, record)
      .then(({ data }) => {
        for (let key in data.data) {
          recordinfo[key] = data.data[key];
        }
      }).finally(() => {
        let time = setInterval(() => {
          ElLoading.service({
            lock: true,
            background: 'rgba(0, 0, 0, 0.7)',
            customClass: 'el-loading'
          }).close()
          loadingrecord.value = false
          clearInterval(time)
        }, 500)

      });
  }
}, {
  immediate: true
})


//dom更新后执行
nextTick(() => {
  let time = setInterval(() => {
    loading.value = false;
    clearInterval(time);
  }, 500);
});
//获取充值记录
// proxy.$get(``);

</script>
<style lang="scss">
.redialog {
  #bigcloser {
    width: 100%;
    @include flex(row, flex-end, center);

    strong {
      display: block;
      width: 28px;
      height: 28px;
    }

    h4 {
      flex: 1;
      font-size: 18px;
      color: #fff;
      text-align: center;
    }

    span {
      display: block;
      width: 28px;
      height: 28px;
      @include flex(row, center, center);
      border: 2px solid #b5b6c8;
      border-radius: 16px;
      margin-right: -7px;
    }
  }

  .el-dialog {
    padding: 15px !important;
    background-color: rgb(50, 53, 62) !important;
    border-radius: 10px !important;
  }

  .dialogmain {
    .confirm {
      background: #0a906c;
      border: none;
      color: #fff;
      display: block;
      width: 40%;
      height: 40px;
      line-height: 40px;
      font-size: 14px;
      color: #fff;
      text-align: center;
      border-radius: 5px;
      margin: 10px auto 20px;
    }

    .note {
      font-size: 14px;
      color: red;
      line-height: 23px;
      margin-top: 10px;
      text-align: left;
    }
  }

  .el-dialog__header {
    padding: 0 !important;
  }
}
</style>
<style scoped lang="scss">
header {
  width: 100%;
  position: fixed;
  left: 0;
  top: 0;
  @include flex(row, space-between, center);
  background-color: rgb(36, 39, 43);
  padding: 20px 20px 6px;
  color: #fff;

  span {
    display: block;
    height: 30px;
    width: 30px;
    @include flex(row, center, center);
    border: 2px solid #fff;
    border-radius: 16px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  strong {
    width: 34px;
    height: 34px;
    display: block;
  }

  dl {
    flex: 1;
    @include flex(row, center, center);

    dd {
      color: #8e8e8c;
      font-size: 18px;
      position: relative;
    }

    .active {
      color: #fff;

      &::after {
        content: "";
        position: absolute;
        width: 60%;
        bottom: -4px;
        height: 2px;
        background-color: #fff;
        margin-left: -30%;
        left: 50%;
      }
    }

    dd+dd {
      margin-left: 20px;
    }
  }
}

.main {
  background-color: #1a1a1a;
  padding: 73px 0px 90px;
  width: 100%;
  min-height: 100vh;
  background-color: rgb(26, 26, 26);

  >ul {
    height: 44px;
    width: 100%;
    padding: 0 16px;
    @include flex(row, flex-start, center);

    li {
      height: 44px;
      @include flex(row, flex-start, center);
      border-bottom: 2px solid transparent;

      img {
        width: 24px;
        margin-right: 5px;
      }

      strong {
        color: #b5bac8;
        font-size: 17px;
      }
    }

    .activeB {
      strong {
        color: #0a906c;
      }

      border-bottom: 2px solid #0a906c;
    }

    li+li {
      margin-left: 20px;
    }
  }

  .record {
    width: 100%;

    dd {
      width: 100%;

      >p {
        height: 40px;
        width: 100%;
        padding: 0 16px;
        line-height: 40px;
        font-size: 14px;
        background-color: #40434c;
        color: #b5bac8;
      }

      .record-item {
        padding: 16px;

        >div {
          @include flex(row, space-between, center);

          p {
            color: #fff;
            font-size: 14px;
          }

          i {
            font-style: normal;
            color: #0a906c;
            font-size: 15px;
          }
        }

        >span {
          font-size: 14px;
          color: #fff;
          display: block;
          margin: 6px 0;
        }

        .status {
          @include flex(row, space-between, center);

          strong {
            color: #666;
            font-weight: normal;
          }

          span {
            font-size: 14px;
            color: #f9e009;
          }
        }
      }

      .record-item+.record-item {
        border-top: 1px solid #40434c;
      }
    }

  }

  .nodata {
    width: 100%;
    height: 400px;

    img {
      width: 200px;
    }

    @include flex(column, center, center);

    p {
      font-size: 17px;
      color: #b5bac8;
      margin-top: 50px;
    }
  }
}
</style>
